package com.pai4j.user.controller;

import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.domain.vo.request.request.SlideVerificationVO;
import com.pai4j.remote.user.SlideVerificationClient;
import com.pai4j.user.service.SlideVerificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  滑块验证配置接口
 *
 * @author: CYM-pai
 * @date: 2025/06/29 21:18
 **/
@RestController
public class SlideVerificationController implements SlideVerificationClient {

    @Autowired
    private SlideVerificationService slideVerificationService;
    
    
   /**
     * 保存滑块验证信息
     *
     * @param slideVerificationVO 滑块验证信息
     * @return 保存结果
     */
  
    public PAIResponseBean<Long> save(@RequestBody SlideVerificationVO slideVerificationVO) {
        Long id = slideVerificationService.save(slideVerificationVO);
        return PAIResponseBeanUtil.success(id);
    }

    /**
     * 更新滑块验证信息状态
     *
     * @param id     滑块验证信息id
     * @param status 状态
     * @return 更新结果
     */
    
    
    public PAIResponseBean<Long> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        slideVerificationService.updateStatus(id, status);
        return PAIResponseBeanUtil.success();
    }

    /**
     * 获取滑块验证信息
     *
     * @return 滑块验证信息
     */
    
   
    public PAIResponseBean<SlideVerificationVO> get() {
        SlideVerificationVO slideVerification = slideVerificationService.get();
        return PAIResponseBeanUtil.success(slideVerification);
    }

    /**
     * 验证滑块验证结果
     *
     * @param accessToken 滑块验证结果
     * @return 验证结果
     */
    
    public PAIResponseBean<Boolean> validate(@PathVariable String accessToken) {
        boolean validateResult = slideVerificationService.validate(accessToken);
        return PAIResponseBeanUtil.success(validateResult);
    }

    /**
     *  分页获取滑块验证列表
     *
     * @author: CYM-pai
     * @date: 2025/06/29 21:44
     **/
  
    
    public PAIPageResponseBeanUtil<SlideVerificationVO> page(@RequestParam(value = "status", required = false) Integer status,
                                                             @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return slideVerificationService.pageList(status, pageNo, pageSize);
    }
}
